<template>
	<view>
		<u-navbar title="我的佣金" back-icon-color="#000" title-color="#000" :title-bold="true" :immersive="true"
			:border-bottom="false" :background="{background:'none'}"></u-navbar>
		<view class="m-head">
			<image src="../static/bg_my balance.png" mode=""></image>
			<view class="m-head-view">
				<view class="m-head-font1">
					<text>{{tixian ||0}}</text>
				</view>
				<view class="m-head-font2">
					<text>我的佣金</text>
				</view>
			</view>
			<view class="m-head-btn" @click="show = true">
				<text>提现</text>
			</view>
		</view>

		<view class="m-tab">
			<view class="m-tab-item" :class="{'m-tab-active':item.value == params.type}" @click="tabItemFun(item)" v-for="(item,index) in tabList" :key="index">
				<text>{{item.name}}</text>
			</view>
		</view>
		<view class="m-list">
			<view class="m-item-view"  v-for="(item,index) in list" :key="index">
				<view class="m-item-top">
					<view class="m-item-top__left">
						<!-- <text style="color: #34302D;">备注：</text> -->
						<text>{{item.remark}}</text>
					</view>
					<view class="m-item-top__right" v-if="item.type == 1">
						<text>消费</text>
					</view>
					<view class="m-item-top__right" v-if="item.type == 2">
						<text>收入</text>
					</view>
					<view class="m-item-top__right" v-if="item.type == 3">
						<text>提现</text>
					</view>
					<!-- <view class="m-item-bottom__right">
						<text>会员卡</text>
					</view> -->
				</view>
				<view class="m-item">
					<view class="m-item-image" v-if="item.from_user">
						<image :src="item.from_user.image" mode="aspectFill"></image>
					</view>
					<view class="m-item-content">
						<view class="u-flex u-row-between">
							<view class="m-item-font1" style="width: 550rpx;" v-if="item.from_user">
								<text>{{item.from_user.phone}}</text>
								<view class="m-item-tip">
									<text>{{ item.from_user.title }}</text>
								</view>
								<!-- <image src="../static/huangjin.png" mode=""></image> -->
							</view>
							<view class="m-item-font1" style="width: 550rpx;" v-else>
								<text>{{item.orderInfo}}</text>
								<!-- <image src="../static/huangjin.png" mode=""></image> -->
							</view>
							<view class="m-item-font3">
								<text v-if="item.type == 2">{{item.money}}</text>
								<text v-else style="color: #D3A358;">{{item.money}}</text>
							</view>
						</view>
						<view class="u-flex u-row-between u-m-t-10">
							<view class="m-item-font2">
								<text>{{item.dtTime}}</text>
							</view>
							<view class="m-item-font2">
								<text>剩余：{{item.yue}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="m-empty" v-if="loading=='noMore' && list.length ==0">
			<image src="../static/fensi-empty.png" mode=""></image>
			<view class="">
				<text>暂无数据~</text>
			</view>
		</view>
		<uni-load-more :status="loading" v-else></uni-load-more>
		
	<!-- 提现 -->
	<u-popup v-model="show" mode="center" border-radius="20" :closeable="true">
		<view class="m-popup">
			<view class="m-popup-title">
				<text>提现</text>
			</view>
			<view class="m-popup-subtitle">
				<text>每月固定10号提现</text>
			</view>
			<view class="m-popup-box">
				<text>提现到</text>
				<text class="u-m-l-20" style="color: #222;">微信零钱</text>
			</view>
			<view class="m-popup-h3">
				<text>提现金额</text>
			</view>
			<view class="m-popup-input">
				<view class="m-popup-label">
					<text>￥</text>
				</view>
				<view class="m-popup-input-box">
					<input type="number" v-model="money">
				</view>
			</view>
			<view class="m-popup-text">
				<text>当前余额￥{{tixian}}元，</text>
				<text style="color: #D3A358;" @click="money = tixian">全部提现</text>
			</view>
			<view class="m-popup-btn" @click="submitFun">
				<text>提现</text>
			</view>
		</view>
	</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show:false,
				tabList:[
					{name:'全部',value:0},
					{name:'获取记录',value:2},
					{name:'提现记录',value:3},
				],
				
				tixian:0,
				loading:'loading',
				params:{
					page:1,
					pagenum:10,
					type:0
				},
				list:[],
				
				money:'',
			}
		},
		onReachBottom() {
			if(this.loading == 'more'){
				this.getListFun()
			}
		}, 
		onLoad() {
			this.getListFun()
		},
		methods: {
			submitFun(){
				if(this.$u.test.empty(this.money)){
					return this.$m.msg('请输入提现金额')
				}
				this.$http.getJson('money_tixian',{
					money:this.money,
					type:1
				}).then(res=>{
					if(res.code == 1){
						this.params.page = 1
						this.list = []
						this.show = false
						this.getListFun()
					}else{
						this.$m.msg(res.message)
					}
				})
			},
			tabItemFun(item){
				this.params.type = item.value
				this.params.page = 1
				this.list = []
				this.getListFun()
			},
			getListFun(){
				this.loading = 'loading'
				let params = this.params
				this.$http.getJson('users_moneyRecord',params).then(res=>{
					if(res.code == 1){
						let list = res.data
// 						list =  [
// {
// "money": "0.30", //金额
// "yue": "0.60", //变动之后用户的余额
// "type": 2, //类型(0所有   1消费   2收入    3提现)
// "dtTime": "2020-01-14 10:41:06", //时间
// "remark": "下下级返利", //类型说明
// "orderInfo": "下下级返利，订单号：1009_2020011410364016540" //返利详细说明
// },
// {
// "money": "0.30", //金额
// "yue": "0.30", //变动之后用户的余额
// "type": 2, //类型(0所有   1消费   2收入    3提现)
// "dtTime": "2020-01-14 10:41:06", //时间
// "remark": "下级返利", //类型说明
// "orderInfo": "下级返利，订单号：1009_2020011410364016540" //返利详细说明
// }
// ]
						let len = list.length
						this.tixian = res.money ? Number(res.money) : 0
						if(len > 0){
							this.list = this.list.concat(list)
						}
						if(len == params.pagenum){
							this.loading = 'more'
							params.page += 1
						}else{
							this.loading = 'noMore'
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f6f6f6;
	}

	.m-head {
		position: relative;
		z-index: 1;
		width: 750rpx;
		height: 460rpx;
		.m-head-btn{
			position: absolute;
			top: 332rpx;
			right: 24rpx;
			z-index: 10;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 120rpx;
			height: 60rpx;
			background: #D3A358;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			font-size: 26rpx;
			color: #fff;
		}

		image {
			position: absolute;
			z-index: -1;
			width: 100%;
			height: 100%;
			top: 0;
			left: 0;
		}

		.m-head-view {
			position: relative;
			padding-top: 300rpx;
			height: 100%;


			.m-head-font1 {
				font-size: 48rpx;
				color: #34302D;
				line-height: 64rpx;
				text-align: center;
			}

			.m-head-font2 {
				font-size: 24rpx;
				color: #906F4C;
				text-align: center;
			}
		}
	}
	.m-tab{
		display: flex;
		align-items: center;
		width: 750rpx;
		background: #fff;
		height: 100rpx;
		.m-tab-item{
			position: relative;
			display: flex;
			justify-content: center;
			align-items: center;
			flex: 1;
			height: 100%;
			font-size: 28rpx;
			color: #75706A;
		}
		.m-tab-active{
			font-size: 32rpx;
			color: #34302D;
			font-weight: 600;
			&::after{
				content: '';
				position: absolute;
				bottom: 0;
				left: 50%;
				transform: translateX(-50%);
				width: 56rpx;
				height: 6rpx;
				background: #D3A358;
			}
		}
	}

	.m-title {
		font-size: 30rpx;
		color: #222;
		line-height: 40rpx;
		font-weight: 600;
		padding-left: 25rpx;
		padding-bottom: 30rpx;
	}

	.m-list {
		padding-top: 20rpx;
		.m-item-view{
			background: #fff;
			padding: 0 25rpx;
			margin-bottom: 20rpx;
		}
		.m-item-top{
			display: flex;
			align-items: center;
			justify-content: space-between;
			border-bottom: 1px solid #EAEAEA;
			height: 92rpx;
			.m-item-top__left{
				font-size: 24rpx;
				color: #9B958F;
			}
			.m-item-top__right{
				display: flex;
				justify-content: center;
				align-items: center;
				height: 36rpx;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
				opacity: 1;
				border: 2rpx solid #D3A358;
				padding: 0 15rpx;
				font-size: 20rpx;
				color: #D3A358;
			}
		}
		.m-item {
			display: flex;
			align-items: center;
			width: 700rpx;
			padding: 30rpx 0;
			

			.m-item-image {
				width: 90rpx;
				height: 90rpx;
				flex-shrink: 0;

				image {
					width: 100%;
					height: 100%;
					border-radius: 50%;
				}
			}

			.m-item-content {
				padding-left: 25rpx;
				flex: 1;
				.m-item-font1 {
					display: flex;
					align-items: center;
					font-size: 30rpx;
					color: #000;

					image {
						width: 80rpx;
						height: 36rpx;
						margin-left: 15rpx;
					}
					.m-item-tip{
						padding: 0 15rpx;
						height: 36rpx;
						line-height: 36rpx;
						background: linear-gradient( 180deg, #EBEBEB 0%, #D1D1D1 100%);
						border-radius: 20rpx ;
						font-size: 20rpx;
						color: #34302D;
						margin-left: 10rpx;
					}
				}

				.m-item-font2 {
					font-size: 24rpx;
					color: #9A958F;
				}
				.m-item-font3{
					font-size: 26rpx;
					color: #34302D;
				}
			}
		}
	}

	.m-empty {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		padding: 60rpx 0 0;
		font-size: 26rpx;
		color: #ADAAA5;

		image {
			width: 320rpx;
			height: 260rpx;
			margin-bottom: 30rpx;
		}
	}

	.m-bottom {
		position: fixed;
		bottom: 0;
		z-index: 10;
		width: 750rpx;
		height: 120rpx;
		background: #fff;
		display: flex;
		justify-content: center;
		align-items: center;
		box-sizing: content-box;
		box-shadow: 0rpx -4rpx 10rpx 1rpx rgba(0, 0, 0, 0.06);

		.m-bottom-btn {
			display: flex;
			justify-content: center;
			align-items: center;
			width: 702rpx;
			height: 104rpx;
			background: #D3A358;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			font-size: 32rpx;
			color: #FFFFFF;
		}
	}

	.m-bottom-empty {
		width: 100%;
		height: 150rpx;
		box-sizing: content-box;
	}
	
	.m-popup{
		width: 640rpx;
		height: 793rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		.m-popup-title{
			display: flex;
			justify-content: center;
			align-items: center;
			height: 128rpx;
			font-size: 32rpx;
			color: #222222;
			font-weight: 600;
		}
		.m-popup-subtitle{
			font-size: 28rpx;
			color: #999999;
			text-align: center;
		}
		.m-popup-box{
			display: flex;
			align-items: center;
			padding-left: 20rpx;
			width: 540rpx;
			height: 80rpx;
			background: #F5F5F5;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			margin: 20rpx auto 0;
			font-size: 28rpx;
			color: #999;
		}
		.m-popup-h3{
			font-size: 34rpx;
			color: #222;
			padding: 60rpx 50rpx 0;
			font-size: 34rpx;
		}
		.m-popup-input{
			display: flex;
			align-items: center;
			width: 540rpx;
			height: 160rpx;
			border-bottom: 1px solid #DDDDDD;
			margin-left: 50rpx;
			.m-popup-label{
				font-size: 54rpx;
				color: #222222;
				font-weight: 600;
			}
			.m-popup-input-box{
				flex: 1;
				height: 100%;
				font-size: 72rpx;
				color: #222222;
				font-weight: 600;
				padding-left: 10rpx;
				input{
					width: 100%;
					height: 100%;
				}
			}
		}
		.m-popup-text{
			padding: 30rpx 50rpx 0;
			font-size: 26rpx;
			color: #9A958F;
		}
		.m-popup-btn{
			display: flex;
			justify-content: center;
			align-items: center;
			width: 540rpx;
			height: 80rpx;
			background: #D3A358;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			margin: 60rpx auto 0;
			font-size: 28rpx;
			color: #fff;
		}
	}
</style>